<?php

namespace App\Http\Controllers\Admin;

use App\Models\Goods;
use App\Models\Order;

Class OrderController extends BaseController{

    public function __construct(Order $order,Goods $goods)
    {
        parent::__construct();
        $this->order = $order;
        $this->goods = $goods;
    }

    /**
     * 获取订单列表 订单管理首页
     */
    public function getOrderList(){

        $res = $this->order->getOrderList(request());
        $flag = 'order';
        //dd($_GET['status']);
        if(!isset($_GET['p'])||$_GET['p'] == 0){
            $temp = 'agent.order.order0';
        }elseif($_GET['p'] == 1){
            $temp = 'agent.order.order1';
        }elseif($_GET['p'] == 2){
            $temp = 'agent.order.order2';
        }elseif($_GET['p'] == 3){
            $temp = 'agent.order.order3';
        }
        //dd($res);
        return view($temp,compact('res','flag'));
        //return ajax_return($res);
    }

    public function getOrderInfo(){
        $data = $this->order->getOrderInfoById(request('id'));
        return ajax_return($data);
    }
    /**
     * 统计订单信息(做图表)
     */
    public function getOrderCount(){
         $res = $this->order->OrderCount();
         $flag = 'brand';

        //return view('admin.brand.charts',compact('res'));
        return view('admin.brand.agent_count',compact('res','flag'));
    }

    /**
     * 订单确认发货
     */
    public function postSendGoods(){
         return $this->order->chageOrderStatus(request());
         return ajax_return($res);
    }

     /**
      * 改变订单状态(确认收款)
      */
    public function getChangeState(){
         $res = $this->order->getChangeState(request());
         return ajax_return($res);
    }

    //订单详情
    public function getOrderDetail()
    {
        $data['order'] = $this->order->getOrderInfoById(request('id'));
        $data['goods'] = $this->goods->getGoodsInfoById($data['order']['goods_id']);
        $flag = 'order';
        //dd($data);
        return view('agent.order.order_detail',compact('data','flag'));

    }


}